package com.zhoux.ty.web.controller;

import com.zhoux.ty.domain.JsonResult;
import com.zhoux.ty.domain.SysUser;
import com.zhoux.ty.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: taoyi
 * @date: 2021/7/30 9:15
 * @version: 1.0
 * @explain:
 */
@Api(tags = "用户控制器")
@RestController
@RequestMapping(value = "/user")
public class SysUserController {

    @Autowired
    private SysUserService userService;

    /**
     * 用户登录
     * @param user
     * @return
     */
    @ApiOperation(value = "用户登录",notes = "")
    @PostMapping(value = "/login")
    public JsonResult login(@RequestBody SysUser user){
        String token = userService.login(user);
        if (token==null){
            return new JsonResult(0);
        }
        return new JsonResult(token);
    }

    /**
     * 用户注册
     * @param user
     * @return
     */
    @ApiOperation(value = "用户注册",notes = "")
    @PostMapping(value = "/register")
    public JsonResult register(@RequestBody SysUser user){
        int reg = userService.register(user);
        if (reg!=0){
            return new JsonResult("注册成功！");
        }else {
            return new JsonResult("注册失败！");
        }
    }


}
